home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 9
/
FM Towns Free Software Collection 9.iso
/
t_os
/
tool
/
tetujin
/
src
/
g_eff
/
midflt.c
< prev
next >
Wrap
Text File
|
1994-11-16
|
3KB
|
170 lines
/*
graphic effect lib.
h. Toda 1994 8 22
*/
#include <stdio.h>
#include <stdlib.h>
#include <egb.h>
#include "g_eff.h"
#define NOERR 0 /* no error */
static int mx ;
static int aSen ;
static int mSen ;
static int cMax ;
static int aMax ;
static int x1 ;
static int y1 ;
static int x2 ;
static int y2 ;
static int (*read1)() ;
static int (*read2)() ;
static int (*write)() ;
static int (*mask)() ;
g_s_c_Filter( BASICPARA *para, int rate )
{
unsigned char a[3][4] ;
int add[256] ;
int i, x, y ;
int n ;
mx = para->mix ;
aSen = para->alphaSen ;
mSen = para->maskSen ;
cMax = para->colorMax ;
aMax = para->alphaMax ;
x1 = para->lupx ;
y1 = para->lupy ;
x2 = para->rdwx ;
y2 = para->rdwy ;
read1 = para->read1 ;
read2 = para->read2 ;
write = para->write ;
mask = para->mask ;
for( i=0 ; i<256 ; i++ )
{
if( i < rate )
add[i] = 0 ;
else if( i < rate*3 )
add[i] = (i-rate)*(i-rate)*(-2*i + 9*rate)/(4*rate*rate) ;
else if( i < 256 )
add[i] = i ;
}
for( y = y1 ; y <= y2 ; y++ )
{
for( x=x1 ; x <= x2 ; x++ )
{
read1( x, y, a[0] ) ;
read2( x, y, a[1] ) ;
for( i=0 ; i<3 ; i++ )
{
int del ;
del = a[0][i] - a[1][i] ;
if( del >= 0 )
a[2][i] = a[1][i] + add[ del ] ;
else
a[2][i] = a[1][i] - add[ -del ] ;
}
mixWrite( x, y, a[2], a[0] ) ;
}
}
return NOERR ;
}
g_c_m_Filter( BASICPARA *para, int rate )
{
unsigned char a[3][4] ;
int add[256] ;
int i, x, y ;
int n ;
mx = para->mix ;
aSen = para->alphaSen ;
mSen = para->maskSen ;
cMax = para->colorMax ;
aMax = para->alphaMax ;
x1 = para->lupx ;
y1 = para->lupy ;
x2 = para->rdwx ;
y2 = para->rdwy ;
read1 = para->read1 ;
read2 = para->read2 ;
write = para->write ;
mask = para->mask ;
for( i=0 ; i<256 ; i++ )
{
if( i < rate )
add[i] = 0 ;
else if( i < rate*3 )
add[i] = (i-rate)*(i-rate)*(-2*i + 9*rate)/(4*rate*rate) ;
else if( i < 256 )
add[i] = i ;
}
for( y = y1 ; y <= y2 ; y++ )
{
for( x=x1 ; x <= x2 ; x++ )
{
read2( x, y, a[0] ) ;
read1( x, y, a[1] ) ;
for( i=0 ; i<3 ; i++ )
{
int del ;
del = a[0][i] - a[1][i] ;
if( del >= 0 )
a[2][i] = a[1][i] + add[ del ] ;
else
a[2][i] = a[1][i] - add[ -del ] ;
}
mixWrite( x, y, a[2], a[1] ) ;
}
}
return NOERR ;
}
static mixWrite( int x, int y, unsigned char *a, unsigned char *b )
{
unsigned char c[4] ;
int mix ;
if( mSen )
{
if( mask( x, y ) >= mSen )
return NOERR ;
}
mix = mx ;
if( aSen )
{
mix = mix * b[3] / aMax ;
}
c[0] = ( a[0] * mix + b[0] * ( 256 - mix ) + 0x80 ) >> 8 ;
c[1] = ( a[1] * mix + b[1] * ( 256 - mix ) + 0x80 ) >> 8 ;
c[2] = ( a[2] * mix + b[2] * ( 256 - mix ) + 0x80 ) >> 8 ;
c[3] = b[3] ;
if( mix )
{
write( x, y, c ) ;
}
return NOERR ;
}